﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
using IDataAccessLayer;

namespace DataAccessLayer
{
    public class AlbumDal : BaseDal<Album>, IAlbumDal
    {
        public IEnumerable<Album> GetTopSellingAlbums(int count)
        {
            var orderDetailIds = baseContext.OrderDetails.GroupBy(o => o.AlbumId).Select(g => new
            {
                Id = g.Key,
                Count = g.Sum(t => t.Id)
            }).OrderByDescending(o=>o.Count).Take(count).Select(o=>o.Id);
            return objectSet.Where(a => orderDetailIds.Contains(a.Id)).ToList();
        }
    }
}
